/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-02-17
*/
package com.rzico.account.service;

import com.rzico.account.enumx.ReceivableStatusEnum;
import com.rzico.base.BaseMapper;
import com.rzico.base.impl.BaseServiceImpl;
import com.rzico.account.entity.Receivable;
import com.rzico.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rzico.account.mapper.ReceivableMapper;

import java.math.BigDecimal;

/**
 * <pre>
 * 应收款业务类
 * </pre>
 *
 * @author Rzico Boot
 * @version 1.0
 */
@Service
public class ReceivableService extends BaseServiceImpl<Receivable, String> {

    @Autowired
    private ReceivableMapper receivableMapper;

    @Override
    public BaseMapper<Receivable, String> getMapper() {
        return receivableMapper;
    }

//
//    public int receivable(Receivable receivableParam){
//        int affectCount = 0;
//        Receivable receivable = receivableMapper.selectByPrimaryKey(receivableParam.getId());
//        if (null == receivable){
//            throw new CustomException("订单不存在");
//        }
//        if (receivable.getStatus().equals(ReceivableStatusEnum.RECEIVABLE_STATUS_COMPLETE.getId())){
//            throw new CustomException("单据收款已完成");
//        }
//
//        int result = receivable.getAvailableAmount().compareTo(receivableParam.getCurrentAmount());
//        if (result >= 0){
//            receivable.setAmountPaid(receivable.getAmountPaid().add(receivableParam.getCurrentAmount()));
//            affectCount = super.updateByPrimaryKeySelective(receivable);
//            if (affectCount > 0){
//                int result1 = receivable.getAmountPaid().compareTo(receivable.getAmount());
//                if (result1 >= 0){
//                    //更新订单支付状态，请走消息
//                }
//            }
//        }else{
//            throw new CustomException("收款金额大于可收款金额");
//        }
//        return affectCount;
//    }
}
